//
//  ZJDiscussViewController.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/9/2.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJDiscussViewController.h"
#import "LPActivityDetailCommiuncationDetailTableViewCell.h"
#import "ZJDiscussSendMessageView.h"
#import <IQKeyboardManager.h>
#import <AFNetworking.h>
#import "ZJDiscussAddView.h"
#import "ZJDiscussContactsViewController.h"
#import "STPhotoBroswer.h"
//openfire
#import "XMPPRoom.h"
#import "drrr.h"
#import "XMPPRoomCoreDataStorage.h"

#import "ZJLivingDetailTableViewCell.h"
#import "ZJLivingDetailSelfTableViewCell.h"
#import "ZJImageMessageTableViewCell.h"
#import "ZJImageMessageSelfTableViewCell.h"
/**  写总结  */
#import "YBProjectDetailSummarizeViewController.h"

//对方发送消息
#define CellID @"ZJLivingDetailTableViewCell.h"
#define Image_CellID @"ZJImageMessageTableViewCell"
//自己发送消息
#define CellID_self @"ZJLivingDetailSelfTableViewCell"
#define Image_CellID_self @"ZJImageMessageSelfTableViewCell"
@interface ZJDiscussViewController ()<UITableViewDataSource,UITableViewDelegate,ZJSendMessageViewDelegate,CSGrowingTextViewDelegate,ZJDiscussAddViewDelegate,ZJPhotographSelectorDelegate,ZJImageMessageTableViewCellDelegate>
/**  tableT  */

@property (strong, nonatomic) UITableView  *tableView;
/** scrollView */
//@property (nonatomic, strong) UIScrollView *scrollView;
/**  数据  */
@property (strong, nonatomic) NSMutableArray  *dataSouce;
/** 消息视图  */
@property (strong, nonatomic) ZJDiscussSendMessageView *sendView;
/** 加号对应的模块 */
@property (nonatomic, strong) ZJDiscussAddView *addView;

/** 对话列表 */
@property (nonatomic, strong) NSArray *messageArray;
/** 房间id */
@property (nonatomic, strong) NSString *roomjid;
/**小写的房间id */
@property (nonatomic, strong) NSString *lowerRoomjid;

@end

@implementation ZJDiscussViewController

- (void)dealloc{
    [[DRRRManager sharedManager] signout];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(id)init{
    self=[super init];
    if (self){
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshTalkNotification:) name:DRRRRefreshTalksNotification object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onlineNotification:) name:DRRRManager_Online_Notification object:nil];
        
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    IQKeyboardManager *manger = [IQKeyboardManager sharedManager];
    manger.enable = NO;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    IQKeyboardManager *manger = [IQKeyboardManager sharedManager];
    manger.enable = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.rightButton.hidden = NO;
    [self.rightButton setImage:[UIImage imageNamed:@"discuss_nav_people"] forState:UIControlStateNormal];
    self.titlelabel.text = @"讨论室";
    [self addNotifation];
    [self initOpenfire];
    
    [self layoutUI];
}

- (void)addNotifation{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];/**< 键盘将要出现的通知 */
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillDismiss:) name:UIKeyboardWillHideNotification object:nil];/**< 键盘将要消失的通知 */

}



- (void)initOpenfire{
    
    [[DRRRManager sharedManager] signinWithUsername:[ZJUserInfoModel sharedUserInfo].ORG_ACCOUNT.ID password:@"111111" host:kXMPP_HOST isregister:NO];
    
}
//加入房间
-(void)gotoSelectedChatRoomWithPassword:(NSString*)password{
    //设置用户名字
    [DRRRManager sharedManager].username = [ZJUserInfoModel sharedUserInfo].ORG_ACCOUNT.ID;
    [[DRRRChatRoomManager sharedChatRoomManager] queryChatRoomInfo:self.roomjid];
    
    [[DRRRChatRoomManager sharedChatRoomManager] joinInChatRoom:self
     .roomjid withPassword:password];
}


#pragma mark - 键盘处理
/**  键盘处理  */
- (void)keyboardWillShow:(NSNotification *)notification {
    CGFloat curkeyBoardHeight = [[[notification userInfo] objectForKey:@"UIKeyboardBoundsUserInfoKey"] CGRectValue].size.height;
    
    NSTimeInterval interal = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    //计算 视图应该移动的位置
    __weak typeof(self) weakSelf = self;
    [UIView animateWithDuration:interal animations:^{
        weakSelf.tableView.frame = CGRectMake(0, LP_TopHeight, weakSelf.view.width, weakSelf.view.height - LP_TopHeight -49 - curkeyBoardHeight);
        weakSelf.sendView.y = weakSelf.view.height - 49 - curkeyBoardHeight;
    }completion:^(BOOL finished) {
        if (weakSelf.dataSouce.count > 0) {
            [weakSelf.tableView
             scrollToRowAtIndexPath:[NSIndexPath
                                     indexPathForRow:self.dataSouce.count-1
                                     inSection:0]
             atScrollPosition:UITableViewScrollPositionBottom
             animated:YES];

        }
    }];
}

- (void)keyboardWillDismiss:(NSNotification *)notification {
    NSTimeInterval interal = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    //计算 视图应该移动的位置
    __weak typeof(self) weakSelf = self;
    [UIView animateWithDuration:interal animations:^{
        weakSelf.sendView.y = weakSelf.view.height - 49;
        weakSelf.tableView.frame = CGRectMake(0, LP_TopHeight, weakSelf.view.width, weakSelf.view.height - LP_TopHeight - 49);
    }];
}


#pragma mark - 数据

#pragma mark - Notification
- (void)onlineNotification:(NSNotification*)notification{
    BOOL online=[notification.object boolValue];
    if (online) {//登录成功
        [self gotoSelectedChatRoomWithPassword:nil];
        [self reloadTable];
    }
}

-(void)refreshTalkNotification:(NSNotification*)notification{
    [self reloadTable];
}

-(void)reloadTable{
    
    self.dataSouce=[[[DRRRMessage sharedMessage] talksWithJid:self.lowerRoomjid] mutableCopy];
    
    if (self.dataSouce.count > 0) {
        [self.tableView reloadData];
        [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.dataSouce.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:YES];
    }
}

#pragma mark - 界面
- (void)layoutUI{
    [self.view addSubview:self.tableView];
    self.sendView = [ZJDiscussSendMessageView new];
    self.sendView.frame = CGRectMake(0, self.view.height - 49, self.view.width, 49);
    self.sendView.delegate = self;
    [self.view addSubview:self.sendView];
    [self.view addSubview:self.addView];
    
    

    
    [self.view bringSubviewToFront:self.navigView];
    [self.view sendSubviewToBack:self.addView];
    if ([self.model.IS_END integerValue] == 3 ) {
        self.addView.hidden = YES;
        self.sendView.hidden = YES;
        CGRect frame = self.tableView.frame;
        frame.size.height = self.view.height - LP_TopHeight;
        self.tableView.frame = frame;
    }
}


#pragma mark - 私有方法
- (void)action_rightButton:(UIButton *)sender{
    ZJDiscussContactsViewController *vc = [ZJDiscussContactsViewController new];
    vc.ID = self.model.ID;
    [self.navigationController pushViewController:vc animated:YES];
}

/**  项目结束  */
- (void)endProject{
    __weak typeof(self) weakSelf = self;
    [YJProgressHUD show:@"" inView:self.view mode:YJProgressModeLoading];
    NSDictionary *dict = @{@"AI_ID":self.model.ID,@"STATUS": @"2"};
    [NetWorkingManager postWithUrlString:[NetWorkingURL getactmactionActChangeStatusstatus] Parameter:dict Success:^(id object) {
        [YJProgressHUD hide];
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:object];
        if ([model.STATE isEqualToString:@"20000"]) {
            [[NSUserDefaults standardUserDefaults] removeObjectForKey:weakSelf.model.ID];
           /**  活动结束通知  */
            [[NSNotificationCenter defaultCenter] postNotificationName:@"ENDLIFEACT" object:weakSelf];
            [weakSelf.navigationController popToViewController:weakSelf.navigationController.viewControllers[1] animated:YES];
        }else{
            [YJProgressHUD showSuccess:@"网络错误" inview:weakSelf.view];
        }
    } Fail:^(id object) {
        [YJProgressHUD hide];
        [YJProgressHUD showSuccess:@"网络错误" inview:weakSelf.view];
    }];


}

#pragma mark - 监听事件
#pragma mark - ZJDiscussAddViewDelegate 协议方法
- (void)ZJDiscussAddViewDelegate_viewClickTag:(NSInteger)tag{
    __weak typeof(self) weakSelf = self;
    switch (tag) {
        case 0://相册
        {
            [ZJPhotographSelector sharedPhotographSelector].delegate = self;
            [[ZJPhotographSelector sharedPhotographSelector] accessPhotoALbm];
        }
            break;
        case 1://拍照
        {
            [ZJPhotographSelector sharedPhotographSelector].delegate = self;
            [[ZJPhotographSelector sharedPhotographSelector] takingPictures];
        }
            break;
        case 2://写总结
        {
            YBProjectDetailSummarizeViewController *vc = [YBProjectDetailSummarizeViewController new];
            vc.model = self.model;
            vc.block = ^{
               weakSelf.addView.summartoyView.titleLabel.text = @"修改总结";
            };
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 3://结束
        {
            
            UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"是否结束" message:nil preferredStyle:UIAlertControllerStyleAlert];
            [alertController addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
               
                [weakSelf endProject];
                
            }]];
            [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            }]];
            [self presentViewController:alertController animated:YES completion:nil];

        }
            break;
        default:
            break;
    }
}

#pragma mark - ZJPhotographSelectorDelegate( 发送图片 )协议方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    
    NetWorkUploadFileModel *imageModel = [NetWorkUploadFileModel new];
    imageModel.FILE_PATH = UIImageJPEGRepresentation(image, 0.5);
    imageModel.FILE_NAME = [NSDateFormatter stringTimeWithDate:[NSDate date]];
    imageModel.NAME = @"IMG_URL";
    imageModel.FILE_INDEX = @"0";
    NetWorkUpLoadModel *model = [NetWorkUpLoadModel new];
    model.UPLOAD_FILES = @[imageModel];
    [self senderNetWorkingModel:model];
    
}



//网络请求
- (void)senderNetWorkingModel:(NetWorkUpLoadModel *)parameter{
    [YJProgressHUD showMessage:@"发送中..." duration:10 view:self.view];
    __weak typeof(self) weakSelf = self;
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json",@"text/html",@"text/javascript",@"text/plain", nil];
    
    NSString *SYS_ACCOUNTID = ZJUSERINFORMODEL.ORG_ACCOUNT.ID ? ZJUSERINFORMODEL.ORG_ACCOUNT.ID :@"";
    NSString *SYS_PARTYMEMBERID = ZJUSERINFORMODEL.ORG_ACCOUNT.PARTY_MEMBER_ID ? ZJUSERINFORMODEL.ORG_ACCOUNT.PARTY_MEMBER_ID : @"";
    
    //1、把文件对象数组转化成数组
    NSArray *fileArray = [parameter.UPLOAD_FILES yy_modelToJSONObject];
    //2、除去data，得到数组
    __block NSMutableArray *nofileDataArray = [NSMutableArray array];//保存新数组
    
    NSString * dateString = [NSString stringWithFormat:@"FILES_%@_KEYS",[NSString getCurrentDate]];
    
    
    
    [fileArray enumerateObjectsUsingBlock:^(NSMutableDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj removeObjectForKey:@"fileUrl"];
        [nofileDataArray addObject:obj];
    }];

    
    [manager POST:UPLOADURL parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
        [parameter.UPLOAD_FILES enumerateObjectsUsingBlock:^(NetWorkUploadFileModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (obj.FILE_PATH) {
                NSData  *fileData= obj.FILE_PATH;//二进制数据
                NSString *mimeType= @"image/jpeg";//文件类型
       
                //拼接最新的文件名
                NSString *fileName = [NSString stringWithFormat:@"%ld%@",(unsigned long)idx,@".jpg"];
                [formData appendPartWithFileData:fileData name:@"00000" fileName:fileName mimeType:mimeType];
            }
        }];
        
        [formData appendPartWithFormData:[nofileDataArray yy_modelToJSONData] name:dateString];
        [formData appendPartWithFormData:[SYS_ACCOUNTID dataUsingEncoding:NSUTF8StringEncoding] name:SYS_ACCOUNTID];
        [formData appendPartWithFormData:[SYS_PARTYMEMBERID dataUsingEncoding:NSUTF8StringEncoding] name:SYS_PARTYMEMBERID];
        [formData appendPartWithFormData:[[NetWorkingURL imgUtil] dataUsingEncoding:NSUTF8StringEncoding] name:@"ACTION_XML"];
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        //进度
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [YJProgressHUD hide];
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:responseObject];
        if ([model.STATE isEqualToString:@"20000"]) {
            NSArray *array = [responseObject objectForKey:@"UPLOAD_FILES"];
            NSString *imageUrl = [array.firstObject objectForKey:@"FILE_PATH"];
            //发送消息
            [[DRRRMessage sharedMessage] sendMessage:imageUrl inChatRoom:weakSelf.roomjid isImageMessage:YES];
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        //失败
         [YJProgressHUD showMessage:@"图片发送失败" inView:weakSelf.view];
    }];
}



#pragma mark - SendMessageDelegate
- (void)sendMessageWithView:(ZJDiscussSendMessageView *)view showAddView:(BOOL)yesOrNO{
    __weak typeof(self) weakSelf = self;
    if (yesOrNO) {//显示加好模块
        [UIView animateWithDuration:0.25 animations:^{
            weakSelf.tableView.frame = CGRectMake(0, LP_TopHeight, weakSelf.view.width, weakSelf.view.height - LP_TopHeight -49 - weakSelf.addView.height);
            weakSelf.sendView.y = weakSelf.view.height - 49 - weakSelf.addView.height;
            weakSelf.addView.y = weakSelf.view.height - weakSelf.addView.height;
        }completion:^(BOOL finished) {
            if (weakSelf.dataSouce.count > 0) {
                [weakSelf.tableView
                 scrollToRowAtIndexPath:[NSIndexPath
                                         indexPathForRow:self.dataSouce.count-1
                                         inSection:0]
                 atScrollPosition:UITableViewScrollPositionBottom
                 animated:YES];
                
            }
        }];
    }else{
        [UIView animateWithDuration:0.25 animations:^{
            weakSelf.sendView.y = weakSelf.view.height - 49;
            weakSelf.tableView.frame = CGRectMake(0, LP_TopHeight, weakSelf.view.width, weakSelf.view.height - LP_TopHeight - 49);
            weakSelf.addView.y = weakSelf.view.height;
        }];
    }
}
- (void)sendMessageWithView:(ZJDiscussViewController *)view message:(NSString *)message{
    if (message.length > 0) {
        //发送消息
        if ([self.sign_count integerValue] == 0) {
            /**  未签到进行签到  */
            [self sign];
        }
        [[DRRRMessage sharedMessage] sendMessage:message inChatRoom:self.roomjid];
    }
}
- (void)sign{
    
    NSDictionary *dict = @{@"AI_ID":self.model.ID,
                           @"USER_ID":[ZJUserInfoModel sharedUserInfo].USER_MODEL_BOOK.ID? [ZJUserInfoModel sharedUserInfo].USER_MODEL_BOOK.ID :@"",
                           @"TYPE":@"0",
                           @"LNG": @"",
                           @"LAT": @"",
                           @"ADDR": @"",
                           @"MEMBERID": ZJUSERINFORMODEL.ORG_ACCOUNT.PARTY_MEMBER_ID,
                           @"DEPTID": ZJUSERINFORMODEL.DEPT_MODEL_BOOK.ID ? ZJUSERINFORMODEL.DEPT_MODEL_BOOK.ID:@""};
    
    [NetWorkingManager postWithUrlString:[NetWorkingURL mobileSignIn] Parameter:dict Success:^(id object) {
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:object];
        if ([model.STATE isEqualToString:@"20000"]) {
            [MobClick event:[UMMStatisticsString siginAct]];
            self.sign_count = @"1";
        }
        
    } Fail:^(id object) {
        
    }];
    
}


- (void)growingTextView:(CSGrowingTextView *)growingTextView willChangeHeight:(CGFloat)height{
    height = height > 34 ? height :34;
    CGFloat viewHeight = height + 15;
    
    
    self.sendView.frame = CGRectMake(self.sendView.x, self.sendView.bottom - viewHeight, self.sendView.width, viewHeight);
    
    
}

- (void)growingTextView:(CSGrowingTextView *)growingTextView didChangeHeight:(CGFloat)height{
    
    
}

#pragma mark - ZJImageMessageTableViewCellDelegate(点击聊天图片) 协议方法
- (void)ZJImageMessageTableViewCellDelegate_imageViewClick:(NSIndexPath *)indexPath{
    DRRRMessageContent *message = self.dataSouce[indexPath.row];
    STPhotoBroswer *view = [[STPhotoBroswer alloc]initWithFrame:CGRectMake(0, 0,self.view.width , self.view.height) ImageArray:@[message.IMAGE_URL] currentIndex:0];
    [view show];
}

#pragma mark - UITableViewDataSource,UITableViewDelegate
/**  返回组个数  */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
/**  返回cell个数  */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSouce.count;
}
/**  返回cell高度  */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    DRRRMessageContent *model = self.dataSouce[indexPath.row];
    if ([model.MESSAGE_TYPE isEqualToString:@"2"]) {//图片消息
        return (200 + 50) * [UIScreen zj_screenHScale];
    }
    //文字消息
        return model.cellHeigth;
}
/**  cell初始化  */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DRRRMessageContent * model = self.dataSouce[indexPath.row];
    
    if ([model.MESSAGE_TYPE isEqualToString:@"2"]){//图片消息
        if (![model.accountId isEqualToString:[ZJUserInfoModel sharedUserInfo].ORG_ACCOUNT.ID]) {//对方发送
            ZJImageMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Image_CellID];
            cell.indexPath = indexPath;
            cell.delegate = self;
            cell.model = model;
            return cell;
            
        }else{
            ZJImageMessageSelfTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Image_CellID_self];
            cell.indexPath = indexPath;
            cell.delegate = self;
            cell.model = model;
            return cell;
        }
    }else{//文字消息
        if (![model.accountId isEqualToString:[ZJUserInfoModel sharedUserInfo].ORG_ACCOUNT.ID]) {//对方发送
            ZJLivingDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
            cell.model = model;
            return cell;
            
        }else{
            ZJLivingDetailSelfTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID_self];
            
            cell.model = model;
            return cell;
        }
    }
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    DRRRMessageContent *model = self.dataSouce[indexPath.row];
    if ([model.MESSAGE_TYPE isEqualToString:@"2"]) {
        /**  这是放大图片  */
        STPhotoBroswer *broswer = [[STPhotoBroswer alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height) ImageArray:@[model.IMAGE_URL] currentIndex:0];
        [broswer show];

    }
}


#pragma mark - 懒加载
/**  初始化tableView  */
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, LP_TopHeight, self.view.bounds.size.width, self.view.bounds.size.height - LP_TopHeight - 49) style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor themeGrayColor];
        _tableView.separatorColor = [UIColor clearColor];
        _tableView.tableFooterView = [UIView new];
        [_tableView registerClass:[ZJLivingDetailTableViewCell class] forCellReuseIdentifier:CellID];
        [_tableView registerClass:[ZJLivingDetailSelfTableViewCell class] forCellReuseIdentifier:CellID_self];
        [_tableView registerClass:[ZJImageMessageTableViewCell class] forCellReuseIdentifier:Image_CellID];
        [_tableView registerClass:[ZJImageMessageSelfTableViewCell class] forCellReuseIdentifier:Image_CellID_self];
    }
    return _tableView;
}

- (NSMutableArray *)dataSouce{
    if (!_dataSouce) {
        _dataSouce = [NSMutableArray array];
    }
    return _dataSouce;
}

- (NSString *)roomjid{
    if (_roomjid == nil){
        _roomjid = [NSString stringWithFormat:@"%@%@.%@",self.model.ID,kXMPP_SUBDOMAIN,kXMPP_DOMAIN];
        self.lowerRoomjid = [_roomjid lowercaseString];
        
    }
    return _roomjid;
    
}
//- (UIScrollView *)scrollView{
//    if (_scrollView == nil){
//        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, LP_TopHeight, self.view.width, self.view.height - LP_TopHeight)];
//        _scrollView.contentOffset = CGPointMake(0, 0);
//        _scrollView.contentSize = CGSizeMake(_scrollView.width, _scrollView.height);
//        _scrollView.contentOffset = CGPointMake(0, 0);
//        _scrollView.showsVerticalScrollIndicator = NO;
//        _scrollView.showsHorizontalScrollIndicator = NO;
////                _scrollView.scrollEnabled = NO;
//        
//    }
//    return _scrollView;
//}

- (ZJDiscussAddView *)addView{
    if (_addView == nil){
        NSMutableArray *array = [NSMutableArray array];
        if (ZJUSERINFORMODEL.isSecretary) {
            [array addObject:@{@"image":@"discuss_add_photo",@"title":@"相册"}];
            [array addObject:@{@"image":@"discuss_photograph",@"title":@"拍照"}];
            if (self.model.SUMMARY.length != 0) {
                [array addObject:@{@"image":@"discuss_summarize",@"title":@"修改总结"}];
            }else{
                [array addObject:@{@"image":@"discuss_summarize",@"title":@"写总结"}];
            }
            
            [array addObject:@{@"image":@"discuss_end",@"title":@"结束"}];
            
        }else{
            [array addObject:@{@"image":@"discuss_add_photo",@"title":@"相册"}];
            [array addObject:@{@"image":@"discuss_photograph",@"title":@"拍照"}];
        }
        
        _addView = [[ZJDiscussAddView alloc] initWithFrame:CGRectMake(0, [UIScreen zj_screenHeight],self.view.width , 220 * [UIScreen zj_screenHScale]) array:array];
        _addView.delegate = self;
    }
    return _addView;
}

@end
